package com.hfy.music.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hfy.model.po.music.MusicPo;
import com.hfy.model.vo.AlbumVo;
import com.hfy.model.vo.MusicVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @ author 韩
 * time: 2024/5/21 4:09
 */
@Mapper
public interface MusicMapper extends BaseMapper<MusicPo> {

    @Select("SELECT `id`,`name`,`music`,`musician`,`createTime`,`albumId`,`cover`,`duration` FROM `music` order by id LIMIT #{offset},#{pageNum}")
    List<MusicPo> queryByPage(int offset, int pageNum);

    @Select("SELECT `id`,`name`,`music`,`musician`,`createTime`,`albumId`,`cover`,`duration`  FROM `music`")
    List<MusicPo> list();

    @Select("SELECT `id`,`name`,`musician`,`createTime`,`albumId`,`duration` FROM music WHERE CONCAT(`name`,' ',`musician`, ' ', `albumId`) LIKE CONCAT('%', #{key}, '%')")
    List<MusicVo> queryByMusicKey(@Param("key") String key);

    // 这里其实有点瑕疵 一次发行应该发行一个专辑
    @Select("SELECT musician, albumId, MIN(createTime) createTime, MIN(cover) cover FROM music " +
            "WHERE CONCAT(name, ' ', musician, ' ', albumId) LIKE CONCAT('%', #{key}, '%') " +
            "GROUP BY musician, albumId")
    List<AlbumVo> queryByAlbumKey(@Param("key") String key);
}

